﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Web.Security;

namespace PSI
{
    public partial class PodgladEDG1 : System.Web.UI.Page
    {
        LINQDataContext bd = new LINQDataContext();

        protected void Page_Load(object sender, EventArgs e)
        {

            //FormsAuthentication.Initialize();
            //FormsAuthenticationTicket bilet = new FormsAuthenticationTicket(1, "michal", DateTime.Now, DateTime.Now.AddMinutes(15), false, FormsAuthentication.FormsCookiePath);
            //HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(bilet));
            //Response.Cookies.Add(cookie);


            //HttpCookie myCookie = new HttpCookie("UserSettings");
            //myCookie["idFirmy"] = "1";
            //myCookie["login"] = "michal";
            //myCookie.Expires = DateTime.Now.AddMinutes(60);
            //Response.Cookies.Add(myCookie);



            Label1.Text = "  Zalogowano jako: " + Request.Cookies["UserSettings"]["login"] + "  ";

            psi_dane_edg1 dane = new psi_dane_edg1();
            string ID = Request.Cookies["UserSettings"]["idFirmy"];

            var query = from c in bd.psi_dane_edg1s
                        where (c.firma_id==Int32.Parse(ID))
                        select c;

            string idEDG1 = "";

            foreach (var q in query)
            {
                idEDG1 = q.daneedg1_id.ToString();
            }

            if (idEDG1 == "")
            {
                Label107.Visible = true;
            }
            else
            {
                S_PodgladEDG1 podglad = new S_PodgladEDG1();
                List<String> danePobrane = podglad.pobierzDane(ID);
                wypelnijPodglad(danePobrane);

            }

            
            
        }


        public void wypelnijPodglad(List<String> dane)
        {
            Label2.Text = dane[0];
            Label3.Text = dane[1];
            if (dane[2] == "BRAK POLA W BAZIE") Label4.Text = "NIE DOTYCZY";
            else Label4.Text = dane[2];
            Label5.Text = dane[3];
            Label6.Text = dane[4];
            //dane osobowe
            Label7.Text = dane[5];
            Label8.Text = dane[6];
            Label9.Text = dane[7];
            Label10.Text = dane[8];
            if (dane[9] == "0") Label11.Text = "";
            else Label11.Text = dane[9];
            Label12.Text = dane[10];
            Label13.Text = dane[11];
            Label14.Text = dane[12];
            if (dane[13].Trim() == "null")
            {
                Label15.Text = "";
            }
            else Label15.Text = dane[13];
            
            Label16.Text = dane[14];
            Label17.Text = dane[15];
            Label18.Text = dane[16];
            Label19.Text = dane[17];
            Label20.Text = dane[18];
            Label21.Text = dane[19];
            Label22.Text = dane[20];
            Label23.Text = dane[21];
            if (dane[22].Trim() == "null") Label24.Text = "";
            else Label24.Text = dane[22];
            if (dane[23].Trim() == "null") Label25.Text = "";
            else Label25.Text = dane[23];
            if (dane[24].Trim() == "null") Label26.Text = "";
            else Label26.Text = dane[24];
            Label27.Text = dane[25];
            Label28.Text = dane[26];
            Label29.Text = dane[27];
            Label30.Text = dane[28];

            if (dane[29].Trim() == "null") Label31.Text = "";
            else Label31.Text = dane[29];
            if (dane[30].Trim() == "taki sam")
            {
                CheckBox2.Checked = true;
                Label32.Text = "";
            }
            else Label32.Text = dane[30];
            if (dane[31].Trim() == "taki sam")
            {
                CheckBox2.Checked = true;
                Label33.Text = "";
            }
            else Label33.Text = dane[31];
            if (dane[32].Trim() == "taki sam")
            {
                CheckBox2.Checked = true;
                Label34.Text = "";
            }
            else
            {
                if (dane[32].Trim() == "null")
                {
                    CheckBox2.Checked = true;
                    Label34.Text = "";
                }
                else Label34.Text = dane[32];
            }
            if (dane[33].Trim() == "taki sam")
            {
                CheckBox2.Checked = true;
                Label35.Text = "";
            }
            else
            {
                if (dane[33].Trim() == "null")
                {
                    CheckBox2.Checked = true;
                    Label35.Text = "";
                }
                else Label35.Text = dane[33];
            }
            if (dane[34].Trim() == "taki sam")
            {
                CheckBox2.Checked = true;
                Label36.Text = "";
            }
            else Label36.Text = dane[34];
            if (dane[35].Trim() == "taki sam")
            {
                CheckBox2.Checked = true;
                Label37.Text = "";
            }
            else Label37.Text = dane[35];
            if (dane[36].Trim() == "taki sam")
            {
                CheckBox2.Checked = true;
                Label38.Text = "";
            }
            else Label38.Text = dane[36];
            if (dane[37].Trim() == "taki sam")
            {
                CheckBox2.Checked = true;
                Label39.Text = "";
            }
            else Label39.Text = dane[37];
            if (dane[38].Trim() == "taki sam")
            {
                CheckBox2.Checked = true;
                Label40.Text = "";
            }
            else Label40.Text = dane[38];
            Label41.Text = dane[39];
            Label42.Text = dane[40];
            Label43.Text = dane[41];
            //symbole 2007
            Label44.Text = dane[42];
            Label45.Text = dane[43];
            Label46.Text = dane[44];
            Label47.Text = dane[45];
            Label48.Text = dane[46];
            Label49.Text = dane[47];
            Label50.Text = dane[48];
            Label51.Text = dane[49];
            Label52.Text = dane[50];
            Label53.Text = dane[51];
            //2004
            Label54.Text = dane[52];
            Label55.Text = dane[53];
            Label56.Text = dane[54];
            Label57.Text = dane[55];
            Label58.Text = dane[56];
            Label59.Text = dane[57];
            Label60.Text = dane[58];
            Label61.Text = dane[59];
            Label62.Text = dane[60];
            Label63.Text = dane[61];
            //adr glownego miejsca
            if (dane[62].Trim() == "taki sam")
            {
                CheckBox3.Checked = true;
                Label64.Text = "";
            }
            else Label64.Text = dane[62];

            if (dane[63].Trim() == "taki sam")
            {
                CheckBox3.Checked = true;
                Label65.Text = "";
            }
            else Label65.Text = dane[63];
            if (dane[64].Trim() == "taki sam")
            {
                CheckBox3.Checked = true;
                Label66.Text = "";
            }
            else
            {
                if (dane[64].Trim() == "null")
                {
                    CheckBox3.Checked = true;
                    Label66.Text = "";
                }
                else Label66.Text = dane[64];
            }
            if (dane[65].Trim() == "taki sam")
            {
                CheckBox3.Checked = true;
                Label67.Text = "";
            }
            else
            {
                if (dane[65].Trim() == "null")
                {
                    CheckBox3.Checked = true;
                    Label67.Text = "";
                }
                else Label67.Text = dane[65];
            }
            if (dane[66].Trim() == "taki sam")
            {
                CheckBox3.Checked = true;
                Label68.Text = "";
            }
            else Label68.Text = dane[66];
            if (dane[67].Trim() == "taki sam")
            {
                CheckBox3.Checked = true;
                Label69.Text = "";
            }
            else Label69.Text = dane[67];
            if (dane[68].Trim() == "taki sam")
            {
                CheckBox3.Checked = true;
                Label70.Text = "";
            }
            else Label70.Text = dane[68];
            if (dane[69].Trim() == "taki sam")
            {
                CheckBox3.Checked = true;
                Label71.Text = "";
            }
            else Label71.Text = dane[69];
            if (dane[70].Trim() == "taki sam")
            {
                CheckBox3.Checked = true;
                Label72.Text = "";
            }
            else Label72.Text = dane[70];
            //if (dane[71].Trim() == "null")
            //{
            //    CheckBox3.Checked = true;
            //    Label73.Text = "";
            //}
            //else 
            Label73.Text = "";

            //adres korespondencyjny
            if (dane[71].Trim() == "taki sam")
            {
                CheckBox4.Checked = true;
                Label74.Text = "";
            }
            else Label74.Text = dane[71];

            if (dane[72].Trim() == "taki sam")
            {
                CheckBox4.Checked = true;
                Label75.Text = "";
            }
            else Label75.Text = dane[72];
            if (dane[73].Trim() == "taki sam")
            {
                CheckBox4.Checked = true;
                Label76.Text = "";
            }
            else
            {
                if (dane[73].Trim() == "null")
                {
                    CheckBox4.Checked = true;
                    Label76.Text = "";
                }
                else Label76.Text = dane[73];
            }
            if (dane[74].Trim() == "taki sam")
            {
                CheckBox4.Checked = true;
                Label77.Text = "";
            }
            else
            {
                if (dane[74].Trim() == "null")
                {
                    CheckBox4.Checked = true;
                    Label77.Text = "";
                }
                else Label77.Text = dane[74];
            }
            if (dane[75].Trim() == "taki sam")
            {
                CheckBox4.Checked = true;
                Label78.Text = "";
            }
            else Label78.Text = dane[75];
            if (dane[76].Trim() == "taki sam")
            {
                CheckBox4.Checked = true;
                Label79.Text = "";
            }
            else Label79.Text = dane[76];
            if (dane[77].Trim() == "taki sam")
            {
                CheckBox4.Checked = true;
                Label80.Text = "";
            }
            else Label80.Text = dane[77];
            if (dane[78].Trim() == "taki sam")
            {
                CheckBox4.Checked = true;
                Label81.Text = "";
            }
            else Label81.Text = dane[78];
            if (dane[79].Trim() == "taki sam")
            {
                CheckBox4.Checked = true;
                Label82.Text = "";
            }
            else Label82.Text = dane[79];
            
            //szybki kontakt
            Label84.Text = dane[80];
            if (dane[81].Trim() == "null")
            {
                Label85.Text = "";
            }
            else Label85.Text = dane[81];
            if (dane[82].Trim() == "null")
            {
                Label86.Text = "";
            }
            else Label86.Text = dane[82];
            if (dane[83].Trim() == "null")
            {
                Label87.Text = "";
            }
            else Label87.Text = dane[83];

            Label88.Text = dane[84];
            Label89.Text = dane[85];
            Label90.Text = dane[86];
            Label108.Text = dane[87];
            if (dane[88].Trim() == "1")
            {
                CheckBox6.Checked = true;
            }
            else CheckBox6.Checked = false;
            if (dane[89].Trim() == "1")
            {
                CheckBox7.Checked = true;
            }
            else CheckBox7.Checked = false;
            if (dane[90].Trim() == "1")
            {
                CheckBox8.Checked = true;
            }
            else CheckBox8.Checked = false;

            if (dane[91].Trim() == "0") CheckBox5.Checked = true;
            else if (dane[91] == "1") CheckBox9.Checked = true;
            else CheckBox10.Checked = true;

            if (dane[92].Trim() == "1")
            {
                CheckBox11.Checked = true;
            }
            else CheckBox11.Checked = false;
            //firma dokumeny
            Label91.Text = dane[93];
            Label92.Text = dane[94];
            Label94.Text = dane[95];
            if (dane[96].Trim() == "null")
            {
                Label95.Text = "";
            }
            else Label95.Text = dane[96];
            if (dane[97].Trim() == "null")
            {
                Label96.Text = "";
            }
            else Label96.Text = dane[97];
            Label97.Text = dane[98];
            if (dane[99].Trim() == "null")
            {
                Label98.Text = "";
            }
            else Label98.Text = dane[99];
            Label99.Text = dane[100];
            if (dane[101].Trim() == "null")
            {
                Label100.Text = "";
            }
            else Label100.Text = dane[101];
            Label101.Text = dane[102];
            Label102.Text = dane[103];
            
            //rodzaj dokumntacji
            if (dane[104].Trim() == "0") CheckBox12.Checked = true;
            else if (dane[104] == "1") CheckBox13.Checked = true;
            else if (dane[104] == "2") CheckBox14.Checked = true;
            else CheckBox15.Checked = true;

            if (dane[105].Trim() == "1") CheckBox16.Checked = true;
            if (dane[106].Trim() == "1") CheckBox17.Checked = true;
            if (dane[107].Trim() == "1") CheckBox18.Checked = true;
            Label103.Text = dane[108];
            Label104.Text = dane[109];
            Label105.Text = dane[110];
            Label106.Text = dane[111];

        }
    }
}